package com.logistics.map.entity.model;

import com.logistics.inventory.entity.domain.InventoryDetail;
import com.logistics.map.entity.domain.MapComponents;
import com.logistics.pick.entity.domain.PickContainer;
import com.logistics.pick.entity.domain.PickDetail;
import com.logistics.utils.tool.StringUtils;
import lombok.Data;

import java.math.BigDecimal;
import java.util.List;
import java.util.stream.Collectors;

@Data
public class ComponentsEventRow {
    //站点编码
    private String label;

    //站点X轴坐标
    private BigDecimal x;

    //站点Y轴坐标
    private BigDecimal y;

    //站点点位
    private String point;

    //站点区域
    private String area;

    //站点当前托盘数量
    private Integer stratum;

    //站点托盘高度
    private BigDecimal height;

    //站点存放托盘类型(1:川字托盘，2：料框，3：大托盘)
    private String containerType;

    //站点存放的托盘编号
    private String container;

    private List<GoodsRow> goods;

    public ComponentsEventRow(MapComponents components) {
        this.label = components.getLabel();
        this.x = components.getX();
        this.y = components.getX();
        this.point = StringUtils.isNotNull(components.getLocation())?components.getLocation():null;
        this.area = StringUtils.isNotNull(components.getLocationArea())?components.getLocationArea():null;
        this.stratum = StringUtils.isNotNull(components.getCurrentStratum())?components.getCurrentStratum():null;
        this.height = StringUtils.isNotNull(components.getLocationHeight())?components.getLocationHeight():null;
        this.containerType = components.getContainerType();

    }

    public static ComponentsEventRow build(MapComponents components) {
        return new ComponentsEventRow(components);
    }

    public static ComponentsEventRow build(String container, MapComponents components, List<PickDetail> pickDetails) {
        ComponentsEventRow row = new ComponentsEventRow(components);
        row.setContainer(container);
        row.setLabel(components.getLabel());
        row.setPoint(components.getLocation());
        row.setArea(components.getLocationArea());
        row.setStratum(components.getCurrentStratum());
        row.setHeight(components.getLocationHeight());
        row.setContainerType(components.getContainerType());
        row.setGoods(StringUtils.isNotNull(pickDetails) ? pickDetails.stream().map(GoodsRow::build).collect(Collectors.toList()) : null);
        return row;
    }

    public static ComponentsEventRow build(String container, List<InventoryDetail> inventoryDetails, MapComponents components) {
        ComponentsEventRow row = new ComponentsEventRow(components);
        row.setContainer(container);
        row.setLabel(components.getLabel());
        row.setPoint(components.getLocation());
        row.setArea(components.getLocationArea());
        row.setStratum(components.getCurrentStratum());
        row.setHeight(components.getLocationHeight());
        row.setContainerType(components.getContainerType());
        row.setGoods(StringUtils.isNotNull(inventoryDetails) ?
                inventoryDetails.stream().map(GoodsRow::build).collect(Collectors.toList()) : null);
        return row;
    }
}
